<?php

namespace mbilling\BillingBundle\Model;

use Doctrine\ORM\EntityManager;
use mbilling\BillingBundle\Entity\usersBillsCurrencies;


Class UsersBillsCurrenciesModel
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }
    
    public function findAll()
    {
        $currencies = $this->em->getRepository('BillingBundle:usersBillsCurrencies')->findAll();
        return $currencies;
    }

    public function findAllWebmoney()
    {
        $query = $this->em->createQuery('SELECT c FROM BillingBundle:usersBillsCurrencies c where c.is_webmoney=1');
        $currencies = $query->getResult();
        return $currencies;
    }
    
    public function findByPK($id)
    {
        $currencies = $this->em->find('BillingBundle:usersBillsCurrencies', $id);
        return $currencies;
    }
    
    public function findByName($name)
    {
        $cur = $this->em->getRepository('BillingBundle:usersBillsCurrencies')->findOneBy(array('name' => $name));
        return $cur;
    }
    
    public function create($oEntity)
    {
        $this->em->persist($oEntity);
        $this->em->flush();
    }
    
    public function removeByPK($cur_id)
    {
        $cur = $this->em->find('BillingBundle:usersBillsCurrencies', $cur_id);
        $this->em->remove($cur);
        $this->em->flush();
    }
}
?>
